<header class="row">
  <% if Sidekiq.paused? %>
    <div class="col-sm-12">
      <div class="alert alert-danger text-center">
        <h2>SIDEKIQ IS PAUSED!</h2>
      </div>
    </div>
  <% end %>
  <div class="col-sm-12">
    <h3>Recurring Jobs <a style='font-size:50%; margin-left: 30px' href='scheduler/history'>history</a></h3>
  </div>
</header>

<div class="container">
  <div class="row">

    <div class="col-md-9">
      <% if @schedules.length > 0 %>
      <table class="table table-striped table-bordered table-white" style="width: 100%; margin: 0; table-layout:fixed;">
        <thead>
          <th style="width: 30%">Worker</th>
          <th style="width: 15%">Last Run</th>
          <th style="width: 15%">Last Result</th>
          <th style="width: 15%">Last Duration</th>
          <th style="width: 15%">Last Owner</th>
          <th style="width: 15%">Next Run Due</th>
          <th style="width: 10%">Actions</th>
        </thead>
        <% @schedules.each do |schedule| %>
        <% @info = schedule.schedule_info %>
        <tr>
          <td>
            <%= schedule %>
            <td>
              <% prev = @info.prev_run %>
              <% if prev.nil? %>
              Never
              <% else %>
              <%= relative_time(Time.at(prev)) %>
              <% end %>
            </td>
            <td>
              <%= @info.prev_result %>
            </td>
            <td>
              <%= sane_duration @info.prev_duration %>
            </td>
            <td>
              <%= @info.current_owner %>
            </td>
            <td>
              <% next_run = @info.next_run %>
              <% if next_run.nil? %>
              Not Scheduled Yet
              <% else %>
              <%= relative_time(Time.at(next_run)) %>
              <% end %>
            </td>
            <td>
              <form action="<%= "#{root_path}scheduler/#{schedule}/trigger" %>" method="post">
                <%= csrf_tag if respond_to?(:csrf_tag) %>
                <input class="btn btn-danger btn-small" type="submit" name="trigger" value="Trigger" data-confirm="Are you sure you want to trigger this job?" />
              </form>
            </td>
        </tr>
        <% end %>
      </table>
      <% else %>
      <div class="alert alert-success">No recurring jobs found.</div>
      <% end %>
    </div>
  </div>
</div>
